package com.jetgege.smartbox.Tools;

import android.content.Context;
import android.graphics.Color;
import android.os.Handler;
import android.widget.TextView;

import com.kaopiz.kprogresshud.KProgressHUD;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by JJT-ssd on 2017/4/1.
 */

public class Common {
    /**
     * 判断当前号码是否是正确的手机号码
     * @param phoneNumber
     * @return
     */
    public static boolean isPhoneNumber(String phoneNumber) {
        boolean isValid = false;
        CharSequence inputStr = phoneNumber;
        //正则表达式
        String phone="^1[34578]\\d{9}$" ;
        Pattern pattern = Pattern.compile(phone);
        Matcher matcher = pattern.matcher(inputStr);
        if(matcher.matches()) {
            isValid = true;
        }
        return isValid;
    }

    public static void dismissHUD(final KProgressHUD hud)
    {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                hud.dismiss();

            }
        },1000);
    }


    public static void scheduleDismiss(final KProgressHUD hud, int time) {
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                hud.dismiss();
            }
        }, time);
    }
    /**
     * 登录提示
     */
    public static void dialogTip(Context context,String text) {

        TextView tv_Tip = new TextView(context);
        tv_Tip.setText(text);
        tv_Tip.setTextColor(Color.WHITE);
        tv_Tip.setTextSize(18);
        final KProgressHUD hudUNUse = KProgressHUD.create(context)
                .setStyle(KProgressHUD.Style.SPIN_INDETERMINATE)
                .setCustomView(tv_Tip)
                .setCancellable(true)
                .setAutoDismiss(true)
                .show();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                hudUNUse.dismiss();
            }
        }, 1000);
    }
}
